// import { Select } from "antd"
import { SelectProps } from "antd"
import { FC, useEffect, useState } from "react"

import useMemberApi from "@/api/member"
import { SFormItem } from "@/components/common"
import StyleSelect from "@/components/common/styleSelect"
import { useLocale } from "@/locales"

export type CreditRatingSelectorField = {}

export const ICreditRatingSelector: FC<any> = props => {
	const { formatMessage } = useLocale()
	const { queryCreditLevelList } = useMemberApi()
	const { labelProps, name = "creditLevel", rules } = props
	const [options, setOptions] = useState<SelectProps["options"]>([])
	useEffect(() => {
		;(async () => {
			const [err, data] = await queryCreditLevelList({ creditType: 1 })
			if (err) {
				setOptions([])
				return
			}
			setOptions(data.map(item => ({ value: item, label: item })))
		})()
	}, [])

	return (
		<SFormItem name={name} label={`${formatMessage({ id: "label.member.credit_rating" })}:`} rules={rules} {...labelProps}>
			<StyleSelect placeholder={formatMessage({ id: "label.select_all" })} options={options} />
		</SFormItem>
	)
}
